#!/usr/bin/python3
# -*- coding: utf-8 -*-
"""
 @Time    : 2021/1/23 下午4:07
 @Author  : tgy
 
"""
import os
import re


def get_mac(ifname='eth0'):
    ...
    message = os.popen('ifconfig ' + ifname).read()
    mac_str = re.search(r'[0-9a-z]{2}:[0-9a-z]{2}:[0-9a-z]{2}:[0-9a-z]{2}:[0-9a-z]{2}:[0-9a-z]{2}',message).group()
    if mac_str:
        return mac_str


def get_ip(ifname='eth0'):
    message = os.popen('ifconfig ' + ifname).read()
    ip_str = re.search(r'inet\s*(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})', message).group(1)
    return ip_str

if __name__ == '__main__':
    ...
    # print(get_mac(ifname='en0'))
    # print(get_ip(ifname='en0'))
    print(get_mac())
    print(get_ip())
